//
//  CertificationViewModel.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/6/7.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class CertificationViewModel: BaseViewModel {
    var name:String = ""
    var idCard:String = ""
    var isChinese:Bool = false //判断是否是中国用户
    var selectIdentyStr = ""
    var country:String = ""
    lazy var identyRequest:IdentyRequest = {
        let api = IdentyRequest()
        api.dataReformer = self
        api.paramSource = self
        api.delegate = self
        return api
    }()
    
    func sendInformation() {
        self.request(request: identyRequest, success: {[weak self] (result) in
            CYMBShow.showMessage(kText("实名认证成功"))
            NotificationCenter.default.post(name: NSNotification.Name.Exchange.primarycertification, object: nil)
            self?.controller?.navigationController?.popViewController(animated: true)
        }) { (request) in
            CYMBShow.showMessage(request.errorMsg)
        }
    }
    
    func archiveCellKind() {
        var array:[CYTableviewItem] = []
        let itemFir = CYTableviewItem(type: .cyNameWrite, name: "", placeHolder: kText("请输入真实姓名"))
        array.append(itemFir)
        let itemSec = CYTableviewItem(type: .cySelectType, name: kText("请选择证件类型"), placeHolder: "")
        array.append(itemSec)
        let itemThird = CYTableviewItem(type: .cyNameWrite, name: kText(""), placeHolder: kText("请输入证件号码"))
        
        array.append(itemThird)
        cellfactory.iteamArray.append(array)
        
    }
    
}
extension CertificationViewModel:RequestCallBack,RequestDataReformer,RequestParamSource {
    func reform(_ request: BaseRequest, _ data: [String : Any]?) {
        if successBlock != nil {
            successBlock!(data)
        }
    }
    
    func requestDidSucess(_ request: BaseRequest) {
        
    }
    
    func requestDidFail(_ request: BaseRequest) {
        if failBlock != nil {
            failBlock!(request)
        }
    }
    
    func requestParams(_ request: BaseRequest) -> [String : Any]? {
        var pramas: [String:Any] = [:]
        if let _ = request as? IdentyRequest {
            pramas.updateValue(name, forKey: "userName")
            pramas.updateValue(idCard, forKey: "credentialsCode")
            pramas.updateValue("中国", forKey: "country")
            pramas.updateValue(selectIdentyStr == kText("大陆身份证") ? 0 : 1, forKey: "credentialsType")
        }
        
        return pramas
    }
}
